using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using ComputerShopE3.Models;

namespace ComputerShopE3.Controllers
{
    public class ManufacturerController : Controller
    {
        ComputerShopDBEntities1 _db = new ComputerShopDBEntities1();
        //
        // GET: /Manufacturer/

        public ActionResult Index()
        {
            return View(_db.NHA_SAN_XUAT.ToList());
        }

        //
        // GET: /Manufacturer/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /Manufacturer/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Manufacturer/Create

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create([Bind(Exclude="id")] NHA_SAN_XUAT nsxToCreate)
        {
            try
            {
                // TODO: Add insert logic here
                _db.AddToNHA_SAN_XUAT(nsxToCreate);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Manufacturer/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View(_db.NHA_SAN_XUAT.Where(nsx=>nsx.id==id).First());
        }

        //
        // POST: /Manufacturer/Edit/5

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(NHA_SAN_XUAT nsxToEdit)
        {
            try
            {
                // TODO: Add update logic here
                NHA_SAN_XUAT originalNSX = _db.NHA_SAN_XUAT.Where(nsx => nsx.id == nsxToEdit.id).First();
                if (!ModelState.IsValid)
                    return View(originalNSX);
                _db.ApplyPropertyChanges(originalNSX.EntityKey.EntitySetName, nsxToEdit);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
